/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Page5={
    create:function () {
        var page={};
        page.ui=new PIXI.DisplayObjectContainer();
        var arr_0=[];
        var arr_1=[];
        var arr_2=[];
        var gp=Easy.CreateJSONGroup(json_group5,page.ui);

        arr_0.push(gp.p5_0,gp.p5_1,gp.p5_2,gp.p5_3,gp.p5_4,gp.p5_5,gp.p5_6,gp.p5_7);
        arr_1.push(gp.p5_d0,gp.p5_d1);
        arr_2.push(gp.p5_t0,gp.p5_t1,gp.p5_t2,gp.p5_t3);
        for(var i=0;i<arr_0.length;i++)
        {
            arr_0[i].scale.x=1;
            arr_0[i].scale.y=1;
            arr_0[i].aphla=1;

            arr_0[i].anchor.set(0.5,1);
            arr_0[i].y+=arr_0[i].height/2;


            arr_0[i].orginX=arr_0[i].x;
            arr_0[i].orginY=arr_0[i].y;
            page.ui.addChild(arr_0[i]);

            var _mask=new PIXI.Graphics();
            _mask.beginFill(0,1);
            _mask.drawRect(-arr_0[i].width/2,-arr_0[i].height-300,arr_0[i].width,arr_0[i].height+300);
            _mask.x=arr_0[i].x;
            _mask.y=arr_0[i].y;
            _mask.scale.set(1,1);
            arr_0[i].mask=_mask;
            page.ui.addChild(_mask);
        }
        for(var i=0;i<arr_1.length;i++)
        {
            arr_1[i].scale.set(1);
            arr_1[i].aphla=0;
            arr_1[i].orginX=arr_1[i].x;
            arr_1[i].orginY=arr_1[i].y;
            page.ui.addChild(arr_1[i]);
        }

        var tip=Easy.CreateSprite('assets/images/tip.png',915,366,0.5,0.5,0);
        page.ui.addChild(tip);
        var tip1=Easy.CreateSprite('assets/images/tip.png',221,366,0.5,0.5,0);
        tip1.scale.x=-1;
        page.ui.addChild(tip1);

        for(var i=0;i<arr_2.length;i++)
        {
            if(i!=0)
            {
                arr_2[i].scale.set(0.9);
            }
            arr_2[i].alpha=0;
            arr_2[i].orginY=arr_2[i].y;
            page.ui.addChild(arr_2[i]);
        }

        page.In=function () {

            for(var i=0;i<arr_0.length;i++)
            {
                arr_0[i].y=arr_0[i].orginY-50;
                arr_0[i].scale.x=0;
                arr_0[i].scale.y=0;
                arr_0[i].alpha=1;
                // arr_0[i].skew.x=1;
                // TweenMax.to(arr_0[i].skew,1,{delay:0.1*i,x:0,ease:Bounce.easeInOut})
                TweenMax.to(arr_0[i].scale,1,{delay:0.1*i,x:1,y:1,ease:Back.easeOut})
                TweenMax.to(arr_0[i],1,{delay:0.1*i,y:arr_0[i].orginY,alpha:1,ease:Back.easeOut})
            }
            for(var i=0;i<arr_1.length;i++)
            {
                arr_1[i].alpha=0;
                arr_1[i].x=arr_1[i].orginX+Math.random()*100-100/2;
                arr_1[i].y=arr_1[i].orginY+Math.random()*100-100/2;
                TweenMax.to(arr_1[i],0.7,{delay:1+0.2*i,x:arr_1[i].orginX,y:arr_1[i].orginY,alpha:1,ease:Back.easeOut,onCompleteParams:[arr_1[i]],onComplete:function (a) {
                    TweenMax.to(a,1,{x:a.orginX+Math.random()*20-10,y:a.orginY+Math.random()*20-10,yoyo:true,repeat:-1,ease:Cubic.easeInOut})
                }})
            }

            for(var i=0;i<arr_2.length;i++)
            {
                arr_2[i].alpha=0;
                arr_2[i].y=arr_2[i].orginY+25;
                // con
                if(i==0)
                {
                    TweenMax.to(arr_2[i],1,{delay:+3.0*i,y:arr_2[i].orginY,alpha:1,ease:Cubic.easeInOut});
                }
                else if(i!=arr_2.length-1)
                {
                    TweenMax.to(arr_2[i],1,{delay:+3.0*(i-1),y:arr_2[i].orginY,alpha:1,ease:Cubic.easeInOut});
                    TweenMax.to(arr_2[i],1,{delay:3+3.0*(i-1),y:arr_2[i].orginY-25,alpha:0,ease:Cubic.easeInOut});
                }
                else
                {
                    TweenMax.to(arr_2[i],1,{delay:+3.0*(i-1),y:arr_2[i].orginY,alpha:1,ease:Cubic.easeInOut});
                }

                // TweenMax.to(arr_2[i],1,{delay:+3.0*i,y:arr_2[i].orginY,alpha:1,ease:Cubic.easeInOut});
                // if(i!=arr_2.length-1||i!=0)
                // {
                //     TweenMax.to(arr_2[i],1,{delay:3+3.0*i,y:arr_2[i].orginY-25,alpha:0,ease:Cubic.easeInOut});
                // }
            }

            tip.x=915;
            TweenMax.to(tip, 1, {x:915-15,repeat:-1,yoyo:true,ease:Cubic.easeInOut});
            TweenMax.to(tip, 1, {delay:3.5,alpha:1,onComplete:function () {
                document.dispatchEvent(new CustomEvent('Main_EnableTrue'))
            }});

            tip1.x=211;
            TweenMax.to(tip1, 1, {x:211+15,repeat:-1,yoyo:true,ease:Cubic.easeInOut});
            TweenMax.to(tip1, 1, {delay:3.5,alpha:1,onComplete:function () {

            }});

        }
        page.Out=function () {
            console.log('out');
            TweenMax.killAll();

            for(var i=0;i<arr_0.length;i++)
            {
                TweenMax.to(arr_0[i],1,{delay:0.1*i,y:arr_0[i].orginY+300,alpha:0,ease:Back.easeIn})
            }
            for(var i=0;i<arr_1.length;i++)
            {
                TweenMax.to(arr_1[i],0.5,{delay:0.5+0.05*i,x:arr_1[i].orginX+Math.random()*300-300/2,y:arr_1[i].orginY+Math.random()*300-300/2,alpha:0,ease:Back.easeIn})
            }
            TweenMax.to(tip, 1, {delay:0,alpha:0,ease:Linear.easeNone});
            TweenMax.to(tip1, 1, {delay:0,alpha:0,ease:Linear.easeNone});

            for(var i=0;i<arr_2.length;i++)
            {
                TweenMax.to(arr_2[i],1,{alpha:0,ease:Cubic.easeInOut});
            }
        }


        return page;
    }
}